CREATE TABLE [dbo].[TDFACT]
(
[CO_EMPR] [dbo].[TD_VC_002] NOT NULL,
[NU_ANNO] [dbo].[TD_IN_004_ANNO] NOT NULL CONSTRAINT [DF__TDFACT__NU_ANNO__6FE99F9F] DEFAULT (datepart(year,getdate())),
[TI_AUXI_EMPR] [dbo].[TD_VC_001] NOT NULL,
[CO_AUXI_EMPR] [dbo].[TD_VC_020] NOT NULL,
[TI_DOCU] [dbo].[TD_VC_003] NOT NULL,
[NU_DOCU] [dbo].[TD_VC_020] NOT NULL,
[NU_CNTB_EMPR] [dbo].[TD_IN_001_CONT] NOT NULL,
[NU_SECU_FACT] [dbo].[TD_IN_001] NOT NULL,
[CO_SERV_FACT] [dbo].[TD_VC_003] NOT NULL,
[CO_MONE] [dbo].[TD_VC_003] NOT NULL,
[NU_SERV] [dbo].[TD_IN_001] NULL,
[IM_SERV_UNIT] [dbo].[TD_NU_016_004] NOT NULL CONSTRAINT [DF__TDFACT__IM_SERV___72C60C4A] DEFAULT ((0)),
[IM_SERV_ORIG] [dbo].[TD_NU_016_004] NOT NULL CONSTRAINT [DF__TDFACT__IM_SERV___74AE54BC] DEFAULT ((0)),
[IM_IIGV_ORIG] [dbo].[TD_NU_016_004] NOT NULL CONSTRAINT [DF__TDFACT__IM_IIGV___76969D2E] DEFAULT ((0)),
[FA_CAMB] [dbo].[TD_NU_009_004] NOT NULL CONSTRAINT [DF__TDFACT__FA_CAMB__787EE5A0] DEFAULT ((1.000)),
[IM_SERV_CNTB] [dbo].[TD_NU_016_004] NOT NULL CONSTRAINT [DF__TDFACT__IM_SERV___7A672E12] DEFAULT ((0)),
[IM_IIGV_CNTB] [dbo].[TD_NU_016_004] NOT NULL CONSTRAINT [DF__TDFACT__IM_IIGV___7C4F7684] DEFAULT ((0)),
[CO_USUA_CREA] [dbo].[TD_VC_008_USUA] NOT NULL,
[FE_USUA_CREA] [dbo].[TD_DT_001_SIST] NOT NULL CONSTRAINT [DF__TDFACT__FE_USUA___7E37BEF6] DEFAULT (getdate()),
[CO_USUA_MODI] [dbo].[TD_VC_008_USUA] NOT NULL,
[FE_USUA_MODI] [dbo].[TD_DT_001_SIST] NOT NULL CONSTRAINT [DF__TDFACT__FE_USUA___7F2BE32F] DEFAULT (getdate())
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[TDFACT] ADD CONSTRAINT [CK__TDFACT__FA_CAMB__797309D9] CHECK (([FA_CAMB]>=(0)))
GO
ALTER TABLE [dbo].[TDFACT] ADD CONSTRAINT [CK__TDFACT__IM_IIGV___778AC167] CHECK (([IM_IIGV_ORIG]>=(0)))
GO
ALTER TABLE [dbo].[TDFACT] ADD CONSTRAINT [CK__TDFACT__IM_IIGV___7D439ABD] CHECK (([IM_IIGV_CNTB]>=(0)))
GO
ALTER TABLE [dbo].[TDFACT] ADD CONSTRAINT [CK__TDFACT__IM_SERV___73BA3083] CHECK (([IM_SERV_UNIT]>=(0)))
GO
ALTER TABLE [dbo].[TDFACT] ADD CONSTRAINT [CK__TDFACT__IM_SERV___75A278F5] CHECK (([IM_SERV_ORIG]>=(0)))
GO
ALTER TABLE [dbo].[TDFACT] ADD CONSTRAINT [CK__TDFACT__IM_SERV___7B5B524B] CHECK (([IM_SERV_CNTB]>=(0)))
GO
ALTER TABLE [dbo].[TDFACT] ADD CONSTRAINT [CK__TDFACT__NU_ANNO__70DDC3D8] CHECK (([NU_ANNO]>=(0)))
GO
ALTER TABLE [dbo].[TDFACT] ADD CONSTRAINT [CK__TDFACT__NU_CNTB___71D1E811] CHECK (([NU_CNTB_EMPR]>=(1) AND [NU_CNTB_EMPR]<=(99)))
GO
ALTER TABLE [dbo].[TDFACT] ADD CONSTRAINT [XPKFACTURACION] PRIMARY KEY CLUSTERED  ([CO_EMPR], [NU_ANNO], [TI_AUXI_EMPR], [CO_AUXI_EMPR], [TI_DOCU], [NU_DOCU], [NU_CNTB_EMPR], [NU_SECU_FACT]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[TDFACT] ADD CONSTRAINT [PK1_TCFACT_A_TDFACT] FOREIGN KEY ([CO_EMPR], [NU_ANNO], [TI_AUXI_EMPR], [CO_AUXI_EMPR], [TI_DOCU], [NU_DOCU], [NU_CNTB_EMPR]) REFERENCES [dbo].[TCFACT] ([CO_EMPR], [NU_ANNO], [TI_AUXI_EMPR], [CO_AUXI_EMPR], [TI_DOCU], [NU_DOCU], [NU_CNTB_EMPR])
GO
